package com.dingli.service.impl;

import com.dingli.framework.entity.Customtraining;
import com.dingli.framework.entity.Trainmember;
import com.dingli.framework.mapper.CustomtrainingMapper;
import com.dingli.framework.util.Response;
import com.dingli.service.ICustomtrainingService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomtrainingService implements ICustomtrainingService {

    @Autowired
    private CustomtrainingMapper customtrainingMapper;

    @Override
    public Response<PageInfo<Customtraining>> CTselectList(String search, Integer pageNum, Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Customtraining> info = new PageInfo<>(customtrainingMapper.CTselectList(search));
        return new Response<>(200, "success", info);
    }


    @Override
    public Response<List<Customtraining>> CTselectAll(Long ctId) {
        return new Response<>(200, "success", customtrainingMapper.CTselectAll(ctId));
    }

    @Override
    public Response<Object> CTupdateState(String ctId) {
        return new Response<>(200, "success", customtrainingMapper.CTupdateState(ctId));
    }

    @Override
    public Response<Object> CTupdate(String ctId) {
        return new Response<>(200, "success", customtrainingMapper.CTupdate(ctId));
    }

    @Override
    public Response<List<Customtraining>> CTselect(String ctId) {
        return new Response<>(200, "success", customtrainingMapper.CTselect(ctId));
    }

    @Override
    public Response<Long> CTinsert(Customtraining customtraining) {
        int count = customtrainingMapper.CTinsert(customtraining);
        if (count > 0) {
            return new Response(200, "success", customtraining.getCtId());
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> CTupdateById(Customtraining customtraining) {
        int count = customtrainingMapper.CTupdateById(customtraining);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> CTdeleteById(Long ctId) {
        int count = customtrainingMapper.CTdeleteById(ctId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }
}